using System;
using System.ComponentModel;
using System.Data;
using System.Collections.Generic;

namespace PlacementManager
{
    public partial class ContactComponent
    {
        /// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
        [DataObjectMethodAttribute(DataObjectMethodType.Select, true)]
        public List<Contact> SelectAllWVenueId(int venueId,string sortExpression)
        {
            List<Contact> listContact = new List<Contact>();
            PlacementManager.DAL.Contact_DAL o = new PlacementManager.DAL.Contact_DAL();

            DataSet ds = o.SelectAllWVenueId(venueId);

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listContact.Add(new Contact((int)row["ContactId"], (string)row["FirstName"], (string)row["LastName"], (string)row["Title"], (string)row["JobTitle"], (string)row["EmailAddress"], (bool)row["IsAgency"], (bool)row["IsEducator"], (int)row["EducatorTypeId"], (decimal)row["EducatorCurrentRate"], (bool)row["IsActive"], (int)row["DivisionId"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));
            }

            listContact.Sort(new ContactComparer(sortExpression));
            return listContact;
        }

        /// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public List<Contact> SelectAllAvailableForPlacementType(int DivisionId, int PlacementTypeId, string sortExpression)
        {
            List<Contact> listContact = new List<Contact>();
            PlacementManager.DAL.Contact_DAL o = new PlacementManager.DAL.Contact_DAL();
            o.DivisionId = DivisionId;
            DataSet ds = o.SelectAllAvailableForPlacementType(PlacementTypeId);

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listContact.Add(new Contact((int)row["ContactId"], (string)row["FirstName"], (string)row["LastName"], (string)row["Title"], (string)row["JobTitle"], (string)row["EmailAddress"], (bool)row["IsAgency"], (bool)row["IsEducator"], (int)row["EducatorTypeId"], (decimal)row["EducatorCurrentRate"], (bool)row["IsActive"], (int)row["DivisionId"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));
            }

            listContact.Sort(new ContactComparer(sortExpression));
            return listContact;
        }
        
        /// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public List<Contact> SelectAllActiveStartingWith(int DivisionId, string prefix, string sortExpression)
        {
            if (prefix == null)
            {
                prefix = string.Empty;
            }
            if (sortExpression.Length == 0)
            {
                sortExpression = "LastName";
            }
            List<Contact> listContact = new List<Contact>();
            PlacementManager.DAL.Contact_DAL o = new PlacementManager.DAL.Contact_DAL();
            o.DivisionId = DivisionId;
            DataSet ds = o.SelectAllActiveStartingWith(prefix, DivisionId);

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listContact.Add(new Contact((int)row["ContactId"], (string)row["FirstName"], (string)row["LastName"], (string)row["Title"], (string)row["JobTitle"], (string)row["EmailAddress"], (bool)row["IsAgency"], (bool)row["IsEducator"], (int)row["EducatorTypeId"], (decimal)row["EducatorCurrentRate"], (bool)row["IsActive"], (int)row["DivisionId"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));
            }

            listContact.Sort(new ContactComparer(sortExpression));
            return listContact;
        }

        /// <summary>
        /// Selects all records from the database table.
        /// </summary>
        /// <returns>A collection of objects of a type representing a row in the database table.</returns>
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public List<Contact> SelectAllWFirstNameLastName(string firstName, string lastName, string sortExpression)
        {
            
            if (sortExpression.Length == 0)
            {
                sortExpression = "LastName";
            }
            List<Contact> listContact = new List<Contact>();
            PlacementManager.DAL.Contact_DAL o = new PlacementManager.DAL.Contact_DAL();

            DataSet ds = o.SelectAllWFirstNameLastName(firstName, lastName);

            foreach (DataRow row in ds.Tables[0].Rows)
            {
                listContact.Add(new Contact((int)row["ContactId"], (string)row["FirstName"], (string)row["LastName"], (string)row["Title"], (string)row["JobTitle"], (string)row["EmailAddress"], (bool)row["IsAgency"], (bool)row["IsEducator"], (int)row["EducatorTypeId"], (decimal)row["EducatorCurrentRate"], (bool)row["IsActive"], (int)row["DivisionId"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]));
            }

            listContact.Sort(new ContactComparer(sortExpression));
            return listContact;
        }


        /// <summary>
        /// Selects one record from the database table using the primary key.
        /// </summary>
        /// <returns>An object of a type representing a row in the database table.</returns>
        [DataObjectMethodAttribute(DataObjectMethodType.Select, false)]
        public Contact SelectOneWEmailAddress(string emailAddress)
        {
            PlacementManager.DAL.Contact_DAL o = new PlacementManager.DAL.Contact_DAL();
            o.EmailAddress = emailAddress;
            DataTable dt = o.SelectOneWEmailAddress().Tables[0];

            if (dt.Rows.Count > 0)
            {
                DataRow row = dt.Rows[0];
                PlacementManager.Contact ContactToReturn = new PlacementManager.Contact((int)row["ContactId"], (string)row["FirstName"], (string)row["LastName"], (string)row["Title"], (string)row["JobTitle"], (string)row["EmailAddress"], (bool)row["IsAgency"], (bool)row["IsEducator"], (int)row["EducatorTypeId"], (decimal)row["EducatorCurrentRate"], (bool)row["IsActive"], (int)row["DivisionId"], (DateTime)row["DateCreated"], (string)row["CreatedBy"], (DateTime)row["DateUpdated"], (string)row["UpdatedBy"]);
                return ContactToReturn;
            }
            else
            {
                PlacementManager.Contact ContactToReturnEmpty = new PlacementManager.Contact();
                return ContactToReturnEmpty;
            }
        }
    }
}
